'use strict';

angular.module('webpageApp')

.factory('templateHelper', ['$http', '$q', '$filter', function($http, $q,
  $filter) {
  return {
    preview: function(set, absurl) {
      console.log(set, 'saveset');
      console.log(absurl, 'url');
      // console.log(url, 'url');
      var def = $q.defer();
      // var rule = {
      //   name: 'Module',
      //   path: 'div > div > a.title'
      // };
      var newSet = $filter('formatTpl')(set);
      var req = {
        method: 'POST',
        url: 'http://192.168.67.234:3033/parse',
        data: {
          "url": absurl,
          "rules": newSet.list
        }
      };
      $http(req).then(function(res) {
        def.resolve(res);
      }, function(rea) {
        def.reject(rea);
      });
      return def.promise;
    }
  };
}]);
